# $Id: CMakeLists.txt 19 2008-11-15 17:51:18Z rodlima $

macro(append_directory_property _prop _value)
    get_directory_property(oldvalue ${_prop})
    set(newvalue ${oldvalue} ${_value})
    set_directory_properties(PROPERTIES ${_prop} "${newvalue}")
endmacro()

macro(add_diagram _target _dia)
    get_filename_component(namewe ${_dia} NAME_WE)
    add_custom_command(OUTPUT ${namewe}.eps
                       COMMAND dia -e ${namewe}.eps -t eps-builtin ${_dia}
                       DEPENDS ${_dia})
    add_custom_command(OUTPUT ${namewe}.pdf
                       COMMAND epstopdf -o ${namewe}.pdf ${namewe}.eps
                       DEPENDS ${namewe}.eps)
    add_custom_target(${namewe}_${_target} DEPENDS ${namewe}.pdf)

    add_custom_command(TARGET ${_target}
                      PRE_BUILD
                      DEPENDS ${namewe}_${_target})
    add_dependencies(${_target} ${namewe}_${_target})
    append_directory_property(ADDITIONAL_MAKE_CLEAN_FILES ${namewe}.pdf
        ${namewe}.eps)
endmacro()
                    

set(projname projeto)
set(tgtname ${projname}_pt)

set(clearfiles ${projname}.idx ${projname}.aux ${projname}.ilg ${projname}.log
    ${projname}.log ${projname}.lot ${projname}.lof ${projname}.toc
    ${projname}.blg ${projname}.out ${projname}.siglax ${projname}.romanlowx
    ${projname}.romanuppx, ${projname}.greeklowx ${projname}.greekuppx
    ${projname}.miscelanx ${projname}.symbolsx ${projname}.symbols
    ${projname}.sigla ${projname}.lol)

set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
    "${clearfiles}")

add_custom_command(OUTPUT ${projname}.bbl
                   COMMAND pdflatex ${projname}
                   COMMAND bibtex ${projname}
                   DEPENDS ${projname}.bib ${projname}.tex)

add_custom_command(OUTPUT ${projname}.ind
                   COMMAND pdflatex ${projname}
                   COMMAND makeindex ${projname}
                   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../bin/geratss ${projname}
                   COMMAND rm -rf ${projname}.pdf
                   DEPENDS ${projname}.tex)

add_custom_command(OUTPUT ${projname}.pdf
                   COMMAND pdflatex ${projname}
                   COMMAND pdflatex ${projname}
                   DEPENDS ${projname}.tex ${projname}.ind ${projname}.bbl)

add_custom_target(${tgtname} ALL DEPENDS ${projname}.pdf)

add_custom_target(show
                   COMMAND xpdf ${projname}.pdf
                   DEPENDS ${projname}.pdf)

add_diagram(${tgtname} diag_student.dia)
add_diagram(${tgtname} diag_list.dia)
add_diagram(${tgtname} diag_document.dia)
add_diagram(${tgtname} diag_disc_class.dia)
add_diagram(${tgtname} diag_student_parent.dia)
add_diagram(${tgtname} diag_svrel.dia)
add_diagram(${tgtname} diag_planev_ev.dia)
add_diagram(${tgtname} obj_network.dia)

